import LangView from "./LangView";
import ResItem from "../res/ResItem";

const { ccclass, property } = cc._decorator;

@ccclass
export  class LangButton extends LangView{

    updateValue(){
        let button: cc.Button = this.node.getComponent(cc.Button);
        if(this.langID){
            let spriteName =  this.manager.getValue(this.langID);
            if(button && spriteName){
                this.getLoader().loadRes(spriteName,cc.SpriteFrame,(err,item:ResItem)=>{
                    if(err || !this.node){
                        return;
                    }
                    let spriteFrame = item.getRes();
                    button.normalSprite = spriteFrame;
                    button.hoverSprite = spriteFrame;
                    button.disabledSprite = spriteFrame;

                });
            }
        }

        if(this.opt){
            let pressSpriteName =  this.manager.getValue(this.opt);
            if(button && pressSpriteName){
                this.getLoader().loadRes(pressSpriteName,cc.SpriteFrame,(err,item:ResItem)=>{
                    if(err || !this.node){
                        return;
                    }
                    button.pressedSprite = item.getRes();
                   
                });
            } 
        }
       
    }
}
